package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @Description NursingProjectServicelmpl
 * @Author pengtao
 * @Date 2025-05-08  12:05
 */

@Service
public class NursingProjectServicelmpl implements NursingProjectService {

    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    //分页查询
    @Override
    public PageResponse<NursingProjectVo> getByPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingProject> nursingProjects = nursingProjectMapper.selectByPage(name, status);
        PageResponse<NursingProjectVo> nursingProjectVoPageResponse = PageResponse.of(nursingProjects, NursingProjectVo.class);
        return nursingProjectVoPageResponse;

    }

    //增
    @Override
    public void add(NursingProjectVo nursingProjectVo) {
        // NursingProject nursingProject = BeanUtil.toBean(nursingProjectVo, NursingProject.class);
        NursingProject nursingProject = new NursingProject( );
        BeanUtil.copyProperties(nursingProjectVo, nursingProject);
        nursingProjectMapper.insert(nursingProject);
    }

    //查
    @Override
    public NursingProjectVo read(Long id) {
        return nursingProjectMapper.selectById(id);
    }

    //删
    @Override
    public void delete(Long id) {
        nursingProjectMapper.delete(id);
    }

    //改
    @Override
    public void update(NursingProjectVo nursingProjectVo) {
        NursingProject nursingProject = new NursingProject();
        BeanUtil.copyProperties(nursingProjectVo, nursingProject);
        nursingProjectMapper.update(nursingProject);
    }



    @Override
    public List<NursingProjectVo> getAll() {
        List<NursingProjectVo> nursingProjectVos = nursingProjectMapper.getnursingsProjectVo();
            return nursingProjectVos;
    }
    //查询所有



    //禁用启用

    @Override
    public void updateStatus(Long id, Integer status) {
        nursingProjectMapper.updateStatus(new NursingProjectVo(id, status));
    }


}
